home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DRIVES.SWG / 0011_DRIVES6.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  3KB  |  83 lines

  1. {
  2. Author : GAYLE DAVIS
  3.  
  4. > It will check For example, drive A:, and if there is no disk in the
  5. >drive it will return False, if it is ready it will return True..
  6.  
  7. There is a problem that you will have to deal With here from the beginning.
  8. First of all Dos can't easily tell if the problem is that you drive door is
  9. open, say in drive 'A', or if the disk is unformatted or unreadable.  Here
  10. is some code that I use to solve the problem using INT25.  do not TRY THIS
  11. ON A HARD DRIVE.
  12. }
  13. Uses
  14.   Dos;
  15.  
  16. Function DisketteDrives : Integer;
  17. Var
  18.   Regs : Registers;
  19. begin
  20.   FILLChar (Regs, SIZEOF (Regs), #0);
  21.   INTR ($11, Regs);
  22.   if Regs.AX and $0001 = 0 then
  23.     DisketteDrives := 0
  24.   else
  25.     DisketteDrives := ( (Regs.AX SHL 8) SHR 14) + 1;
  26. end;
  27.  
  28. Function IsDriveReady (DriveSpec : Char) : Boolean; {A,B,etc}
  29. Var
  30.   result : Word;
  31.   Drive,
  32.   number,
  33.   logical : Word;
  34.   buf    : Array [1..512] of Byte;
  35.   Regs   : Registers;
  36. begin
  37.   IsDriveReady := True;     { Assume True to start }
  38.   Drive   := ORD (UPCASE (DriveSpec) ) - 65;  { 0=a, 1=b, etc }
  39.  
  40.   if Drive > DisketteDrives then
  41.     Exit;  { do not CHECK HARD DRIVES }
  42.  
  43.   number  := 1;
  44.   logical := 1;
  45.  
  46.   Inline (
  47.     $55 /                       { PUSH BP         ; Interrupt 25 trashes all}
  48.     $1E /                       { PUSH DS         ; Store DS                }
  49.     $33 / $C0 /                 { xor  AX,AX      ; set AX to zero          }
  50.     $89 / $86 / result /        { MOV  Result, AX ; Move AX to Result       }
  51.     $8A / $86 / Drive /         { MOV  AL, Drive  ; Move Drive to AL        }
  52.     $8B / $8E / number /        { MOV  CX, Number ; Move Number to CX       }
  53.     $8B / $96 / logical /       { MOV  DX, Logical; Move Logical to DX      }
  54.     $C5 / $9e / buf /           { LDS  BX, Buf    ; Move Buf to DS:BX       }
  55.     $CD / $25 /                 { INT  25h        ; Call interrupt $25      }
  56.     $5B /                       { POP  BX         ; Remove the flags valu fr}
  57.     $1F /                       { POP  DS         ; Restore DS              }
  58.     $5D /                       { POP  BP         ; Restore BP              }
  59.     $73 / $04 /                 { JNB  Done       ; Jump ...                }
  60.     $89 / $86 / result);        { MOV  Result, AX ; move error code to AX   }
  61.   { Done: }
  62.  
  63.   IsDriveReady := (result = 0);
  64. end;
  65.  
  66. (*
  67. Also, you could change the ISDRIVEREADY Function if you wanted to find out
  68. WHY the drive isn't ready by checking the LO(result). Like this :
  69.  
  70.   if result <> 0 then
  71.   begin
  72.     Case LO (result) OF
  73.       0     : FloppyState := WritePROTECT; { should not ever happen }
  74.       1..4  : FloppyState := DOOROPEN;
  75.       5..12 : FloppyState := NOFORMAT;
  76.       else
  77.         FloppyState := DOOROPEN;
  78.     end
  79.   end
  80.   else
  81.     FloppyState := DRIVEREADY;
  82. *)
  83.